package com.niit.agricstore.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.niit.agricstore.entity.Item;
import com.niit.agricstore.entity.User;
import com.niit.agricstore.mapper.ItemMapper;
import com.niit.agricstore.service.ItemService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements ItemService {
    //库存接口实现
    @Autowired
    ItemMapper itemMapper;
    @Override
    public List<Item> selectByItemId(int itemId) {
        return itemMapper.selectByItemId(itemId);
    }

    @Override
    public PageInfo<Item> findItemAllByPage(Integer pageNum, Integer pageSize) {
      Page<Item> page = new Page<Item>(pageNum,pageSize);
        page = itemMapper.selectPage(page,null);
        List<Item> itemlist = page.getRecords();
        return PageInfo.of(itemlist);
    }


    @Override
    public List<Item> findAllByItemCategory(String itemCategory) {
        return itemMapper.findAllByItemCategory(itemCategory);
    }

    @Override
    public List<Item> findItemStockAndItemShelfLifeByItemId(int itemId) {
        return itemMapper.findItemStockAndItemShelfLifeByItemId(itemId);
    }

    @Override
    public List<Item> findItemUnitPriceByItemId(int itemId) {
        return itemMapper.findItemUnitPriceByItemId(itemId);
    }

    @Override
    public int insertAll(Item item) {
        return itemMapper.insertAll(item);
    }

    @Override
    public int delByItemId(int itemId) {
        return itemMapper.delByItemId(itemId);
    }

    @Override
    public int updateItemStockAndItemProductionDateByItemId(int itemStock, Date itemProductionDate, int itemId) {
        return itemMapper.updateItemStockAndItemProductionDateByItemId(itemStock,itemProductionDate,itemId);
    }

    @Override
    public int updateItemUnitPriceByItemId(BigDecimal itemUnitPrice, int itemId) {
        return itemMapper.updateItemUnitPriceByItemId(itemUnitPrice,itemId);
    }


}
